package com.mmall.service.impl;

import com.alipay.api.domain.ExtendParams;

import com.alipay.demo.trade.model.GoodsDetail;
import com.google.common.collect.Maps;
import com.mmall.common.ServerResponse;
import com.mmall.dao.OrderMapper;
import com.mmall.dao.OrderMapperCustom;
import com.mmall.pojo.Order;
import com.mmall.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.imageio.spi.ServiceRegistry;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author cg.hu
 * @version 1.0.0
 * @date 2021-10-20 13:30
 * @description
 * @since 1.0.0
 */
@Service("iOrderService")
public class OrderServiceImpl implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderMapperCustom orderMapperCustom;

    /**
     * @author cg.hu 
     * @version 1.0.0   
     * @date 2021-10-21 8:37      
     * @description
     **/
    public ServerResponse pay(Long orderNo, Integer userId, String path) {
        Map<String, String> resultMap = Maps.newHashMap();
        Order order = orderMapperCustom.selectByUserIdAndOrderNo(userId, orderNo);
        resultMap.put("orderNo", order.getOrderNo().toString());

        // (必填) 商户网站订单系统中唯一订单号，64个字符以内，只能包含字母、数字、下划线，
        // 需保证商户系统端不能重复，建议通过数据库sequence生成，
        String outTradeNo = order.getOrderNo().toString();

        // 标题
        String subject = new StringBuilder().append("happymall,订单号:").append(orderNo).toString();

        // 订单总金额
        String totalAmount = order.getPayment().toString();

        // 订单不可打折金额
        String undiscountableAmount = "0";

        // 卖家支付宝账号ID, 默认APPID
        String sellerId = "";

        // 订单描述
        String body = new StringBuilder().append("订单号：").append(orderNo).toString();

        // 商户操作员编号
        String operatorId = "";

        // 商户门店编号
        String storeId = "";

        // 业务扩展字段
        ExtendParams extendParams = new ExtendParams();
        extendParams.setSysServiceProviderId("98798797889");

        // 超时时间
        String timeoutExpress = "120m";

        // 商品明细列表，
        List<GoodsDetail> goodsDetailList = new ArrayList<>();
        // 创建一个商品信息, 商品ID， 名称， 单价数量，
        GoodsDetail goods1 = GoodsDetail.newInstance("001", "小面包", 1000,1);
        goodsDetailList.add(goods1);


        return null;
    }

}
